<?php

namespace Gnway\Ticket\Rest\Util;

use InvalidArgumentException;

final class AssertUtils
{

  /**
   * Don't let anyone instantiate this class
   */
  private function __construct() { }

  /**
   * Assert that an param is not null
   *
   * @param mixed  $var
   * @param string $message
   * @param int    $code
   * @return void
   * @throws InvalidArgumentException
   */
  public static function notNull($var, string $message = 'The argument must not be null', int $code = 0): void
  {
    if ($var === NULL) {
      throw new InvalidArgumentException($message, $code);
    }
  }

  /**
   * Assert that an param is null
   *
   * @param mixed  $var
   * @param string $message
   * @param int    $code
   * @return void
   * @throws InvalidArgumentException
   */
  public static function isNull($var, string $message = 'The argument must be null', int $code = 0): void
  {
    if ($var !== NULL) {
      throw new InvalidArgumentException($message, $code);
    }
  }

  /**
   * Assert that an param is not empty
   *
   * @param mixed  $var
   * @param string $message
   * @param int    $code
   * @return void
   * @throws InvalidArgumentException
   */
  public static function notEmpty($var, string $message = 'The argument must not be empty', int $code = 0): void
  {
    if (empty($var)) {
      throw new InvalidArgumentException($message, $code);
    }
  }

  /**
   * Assert that an param is empty
   *
   * @param mixed  $var
   * @param string $message
   * @param int    $code
   * @return void
   * @throws InvalidArgumentException
   */
  public static function isEmpty($var, string $message = 'The argument must be empty', int $code = 0): void
  {
    if (!empty($var)) {
      throw new InvalidArgumentException($message, $code);
    }
  }

  /**
   * Assert that an param type is Array
   *
   * @param mixed  $var
   * @param string $message
   * @param int    $code
   * @return void
   * @throws InvalidArgumentException
   */
  public static function isArray($var, string $message = 'The argument type must be Array', int $code = 0): void
  {
    if (!is_array($var)) {
      throw new InvalidArgumentException($message, $code);
    }
  }

  /**
   * Assert that an param type is not Array
   *
   * @param mixed  $var
   * @param string $message
   * @param int    $code
   * @return void
   * @throws InvalidArgumentException
   */
  public static function notArray($var, string $message = 'The argument type must not be Array', int $code = 0): void
  {
    if (is_array($var)) {
      throw new InvalidArgumentException($message, $code);
    }
  }

  /**
   * Assert that an param type is Object
   *
   * @param mixed  $var
   * @param string $message
   * @param int    $code
   * @return void
   * @throws InvalidArgumentException
   */
  public static function isObject($var, string $message = 'The argument type must be Object', int $code = 0): void
  {
    if (!is_object($var)) {
      throw new InvalidArgumentException($message, $code);
    }
  }

  /**
   * Assert that an param type is not Object
   *
   * @param mixed  $var
   * @param string $message
   * @param int    $code
   * @return void
   * @throws InvalidArgumentException
   */
  public static function notObject($var, string $message = 'The argument type must not be Object', int $code = 0): void
  {
    if (is_object($var)) {
      throw new InvalidArgumentException($message, $code);
    }
  }

  /**
   * Assert that an param type is String
   *
   * @param mixed  $var
   * @param string $message
   * @param int    $code
   * @return void
   * @throws InvalidArgumentException
   */
  public static function isString($var, string $message = 'The argument type must be String', int $code = 0): void
  {
    if (!is_string($var)) {
      throw new InvalidArgumentException($message, $code);
    }
  }

  /**
   * Assert that an param type is not String
   *
   * @param mixed  $var
   * @param string $message
   * @param int    $code
   * @return void
   * @throws InvalidArgumentException
   */
  public static function notString($var, string $message = 'The argument type must not be String', int $code = 0): void
  {
    if (is_string($var)) {
      throw new InvalidArgumentException($message, $code);
    }
  }

  /**
   * Assert that an param type is Number
   *
   * @param mixed  $var
   * @param string $message
   * @param int    $code
   * @return void
   * @throws InvalidArgumentException
   */
  public static function isNumber($var, string $message = 'The argument type must be Number', int $code = 0): void
  {
    if (!is_numeric($var)) {
      throw new InvalidArgumentException($message, $code);
    }
  }

  /**
   * Assert that an param type is not Number
   *
   * @param mixed  $var
   * @param string $message
   * @param int    $code
   * @return void
   * @throws InvalidArgumentException
   */
  public static function notNumber($var, string $message = 'The argument type must not be Number', int $code = 0): void
  {
    if (is_numeric($var)) {
      throw new InvalidArgumentException($message, $code);
    }
  }

  /**
   * Assert that an param type is Float
   *
   * @param mixed  $var
   * @param string $message
   * @param int    $code
   * @return void
   * @throws InvalidArgumentException
   */
  public static function isFloat($var, string $message = 'The argument type must be Float', int $code = 0): void
  {
    if (!is_float($var)) {
      throw new InvalidArgumentException($message, $code);
    }
  }

  /**
   * Assert that an param type is not Float
   *
   * @param mixed  $var
   * @param string $message
   * @param int    $code
   * @return void
   * @throws InvalidArgumentException
   */
  public static function notFloat($var, string $message = 'The argument type must not be Float', int $code = 0): void
  {
    if (is_float($var)) {
      throw new InvalidArgumentException($message, $code);
    }
  }

  /**
   * Assert that an param type is Boolean
   *
   * @param mixed  $var
   * @param string $message
   * @param int    $code
   * @return void
   * @throws InvalidArgumentException
   */
  public static function isBoolean($var, string $message = 'The argument type must be Boolean', int $code = 0): void
  {
    if (!is_bool($var)) {
      throw new InvalidArgumentException($message, $code);
    }
  }

  /**
   * Assert that an param type is not Boolean
   *
   * @param mixed  $var
   * @param string $message
   * @param int    $code
   * @return void
   * @throws InvalidArgumentException
   */
  public static function notBoolean($var, string $message = 'The argument type must not be Boolean', int $code = 0): void
  {
    if (is_bool($var)) {
      throw new InvalidArgumentException($message, $code);
    }
  }

  /**
   * Assert that an param type is Integer
   *
   * @param mixed  $var
   * @param string $message
   * @param int    $code
   * @return void
   * @throws InvalidArgumentException
   */
  public static function isInteger($var, string $message = 'The argument type must be Integer', int $code = 0): void
  {
    if (!is_integer($var)) {
      throw new InvalidArgumentException($message, $code);
    }
  }

  /**
   * Assert that an param type is not Integer
   *
   * @param mixed  $var
   * @param string $message
   * @param int    $code
   * @return void
   * @throws InvalidArgumentException
   */
  public static function notInteger($var, string $message = 'The argument type must not be Integer', int $code = 0): void
  {
    if (is_integer($var)) {
      throw new InvalidArgumentException($message, $code);
    }
  }

  /**
   * Assert that an param type is Resource
   *
   * @param mixed  $var
   * @param string $message
   * @param int    $code
   * @return void
   * @throws InvalidArgumentException
   */
  public static function isResource($var, string $message = 'The argument type must be Resource', int $code = 0): void
  {
    if (!is_resource($var)) {
      throw new InvalidArgumentException($message, $code);
    }
  }

  /**
   * Assert that an param type is not Resource
   *
   * @param mixed  $var
   * @param string $message
   * @param int    $code
   * @return void
   * @throws InvalidArgumentException
   */
  public static function notResource($var, string $message = 'The argument type must not be Resource', int $code = 0): void
  {
    if (is_resource($var)) {
      throw new InvalidArgumentException($message, $code);
    }
  }

  /**
   * Assert that an param type is instanceof a object
   *
   * @param mixed  $var
   * @param string $object
   * @param string $message
   * @param int    $code
   * @return void
   * @throws InvalidArgumentException
   */
  public static function isInstanceof($var, string $object, string $message = 'The object argument type is invalid', int $code = 0): void
  {
    if (!($var instanceof $object)) {
      throw new InvalidArgumentException($message, $code);
    }
  }

  /**
   * Assert that an param type is not instanceof a object
   *
   * @param mixed  $var
   * @param string $object
   * @param string $message
   * @param int    $code
   * @return void
   * @throws InvalidArgumentException
   */
  public static function notInstanceof($var, string $object, string $message = 'The object argument type is invalid', int $code = 0): void
  {
    if ($var instanceof $object) {
      throw new InvalidArgumentException($message, $code);
    }
  }

}